package com.cqc.transition01;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.ViewFlipper;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by cui on 2017/7/20.
 */

public class ViewFlipperActivity extends AppCompatActivity {

    @BindView(R.id.btn1)
    Button btn1;
    @BindView(R.id.btn2)
    Button btn2;
    @BindView(R.id.viewFlipper)
    ViewFlipper viewFlipper;

    private Context context = this;
    private TextView tv;
    private ImageView iv;
    private Switch aSwitch;
    private CheckBox cb;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_flipper);
        ButterKnife.bind(this);

        Animation slide_in = AnimationUtils.loadAnimation(context, android.R.anim.slide_in_left);
        Animation slide_out = AnimationUtils.loadAnimation(context, android.R.anim.slide_out_right);
        viewFlipper.setInAnimation(slide_in);
        viewFlipper.setOutAnimation(slide_out);

        createViews();
        addViews();
    }

    private void addViews() {
        viewFlipper.addView(tv);
        viewFlipper.addView(iv);
        viewFlipper.addView(aSwitch);
        viewFlipper.addView(cb);
    }

    private void createViews() {
        tv = new TextView(context);
        tv.setText("Text");
        tv.setGravity(Gravity.CENTER);

        iv = new ImageView(context);
        iv.setImageResource(R.mipmap.ic_launcher);

        aSwitch = new Switch(context);

        cb = new CheckBox(context);
        cb.setGravity(Gravity.CENTER);
    }

    @OnClick({R.id.btn1, R.id.btn2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                viewFlipper.showPrevious();
                break;
            case R.id.btn2:
                viewFlipper.showNext();
                break;
        }
    }
}
